/**
 * 封装存储localStorage，可以设定过期时间
 * @param {Object} key 存放的key值
 * @param {Object} val 存放的value值
 * @param {Object} time 设定的过期时间,单位为秒
 */
export function loca_setItem(key, val, time) {
	if (time) {
		var value = {
			val: val,
			c_time: new Date().getTime(),
			time: time * 1000
		}
		localStorage.setItem(key, JSON.stringify(value));
	} else {
		localStorage.setItem(key, JSON.stringify(val));
	}
}
/**
 * 封装localStorage的getItem函数
 * @param {Object} key 需要获取的key值
 */
export function loca_getItem(key) {
	if (localStorage.getItem(key)) {
		var val = JSON.parse(localStorage.getItem(key));
		if (val.c_time) {
			var n_time = new Date().getTime();
			if (n_time <= (val.c_time + val.time)) {
				return val.val;
			} else {
				localStorage.removeItem(key);
				return "";
			}
		} else {
			return val;
		}
	} else {
		return "";
	}
}

/**
 * 封装localStorage的removeItem函数
 * @param {Object} key 需要删除的key值
 */
export function loca_removeItem(key) {
	localStorage.removeItem(key);
}

/**
 * 循环删除key数组
 * @param {Object} keys 需要删除的key数组
 */
export function loca_removeItems(keys) {
	for (var k in keys) {
		myapp.loca_removeItem(keys[k]);
	}
}
